class Req < ActiveRecord::Base

  acts_as_versioned

  #has_many :reqrels
  #has_many :subreqs, :through=>:reqrels, :foreign_key=>'req_to_id', :class_name=>'req' #, :select => "memberships.active, projects.*"

  validates_uniqueness_of :reference, :case_sensitive => false, :scope=>:project_id, :allow_blank=>true
  validates_presence_of   :text

  def subreqs
    Req.find_by_sql("select * from reqs where id in (select distinct req_to_id from req_rels where req_from_id='#{self.id}')")
  end

  def fathers
    Req.find_by_sql("select * from reqs where id in (select distinct req_from_id from req_rels where req_to_id='#{self.id}')")
  end

  
end

